package com.zmzncs.lmtc.module.shop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zmzncs.lmtc.common.pojo.PageInfo;
import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.pojo.TypeInfo;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.shop.pojo.shop_info.*;
import com.zmzncs.lmtc.module.shop.service.ShopInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商户-信息 前端控制器
 * </p>
 *
 * @author 高博文
 * @since 2021-05-20
 */
@Api(tags = "商户信息")
@RestController
@RequestMapping("/shop/shop-info")
public class ShopInfoController {
    @Autowired
    ShopInfoService shopInfoService;


    @ApiOperation(value = "创建商户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("add")
    public Rest add(@Valid ShopInfoAddForm form){
        shopInfoService.add(form);

        return RestUtil.success();
    }

    @ApiOperation(value = "查询经营类型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping("getBusinessType")
    public Rest<List<TypeInfo>> getBusinessType(){

        List<TypeInfo> list = new ArrayList<>();
        TypeInfo type1 = new TypeInfo(1,"餐饮");
        list.add(type1);
        TypeInfo type2 = new TypeInfo(2,"加油站");
        list.add(type2);
        TypeInfo type3 = new TypeInfo(3,"洗车");
        list.add(type3);
        TypeInfo type4 = new TypeInfo(4,"养车");
        list.add(type4);
        TypeInfo type5 = new TypeInfo(5,"商超");
        list.add(type5);
        TypeInfo type6 = new TypeInfo(6,"其他");
        list.add(type6);

        return RestUtil.success(list);
    }

    @ApiOperation(value = "条件分页查询商户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("getShopInfoPage")
    public Rest<PageInfo<ShopInfoTableVO>> getShopInfoPage(@Valid ShopInfoSelectForm form){
        IPage<ShopInfoDTO> shopInfoPage = shopInfoService.getShopInfoPage(form);
        PageInfo<ShopInfoTableVO> pageInfo = JsonUtil.pageTransform(shopInfoPage, ShopInfoTableVO.class);
        return RestUtil.success(pageInfo);
    }

    @ApiOperation(value = "商户—修改展示状态")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "shopId", value = "商户ID", required = true),
            @ApiImplicitParam(paramType="query", name = "status", value = "状态（1：展示，0：不展示）", required = true),
    })
    @PostMapping("updateStatus")
    public Rest updateStatus(@NotNull Long shopId, @NotNull Integer status){

        ShopInfo shopInfo = new ShopInfo();
        shopInfo.setId(shopId);
        shopInfo.setStatus(status);
        shopInfoService.updateById(shopInfo);

        return RestUtil.success();
    }

    @ApiOperation(value = "根据id查询商户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType="query", name = "shopId", value = "商户ID", required = true),
    })
    @GetMapping("getShopById")
    public Rest<ShopInfoVO> getShopById(@NotNull Long shopId){

        ShopInfoDTO  shopInfoDTO = shopInfoService.getShopById(shopId);
        ShopInfoVO shopInfoVO = new ShopInfoVO();
        BeanUtils.copyProperties(shopInfoDTO,shopInfoVO);

        return RestUtil.success(shopInfoVO);
    }

    @ApiOperation(value = "修改商户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @PostMapping("update")
    public Rest update(@Valid ShopInfoUpdateForm form){
        shopInfoService.updateShopInfo(form);

        return RestUtil.success();
    }


    @ApiOperation(value = "查询所有商户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping("shopInfoList")
    public Rest<List<ShopInfoDTO>> shopInfoList(){
        List<ShopInfoDTO> shopInfos = shopInfoService.shopInfoList();

        return RestUtil.success(shopInfos);
    }

    @ApiOperation(value = "查询没有配置管理员的商户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
    })
    @GetMapping("get-no_manager")
    public Rest<List<ShopInfoDTO>> getNoManager(){
        List<ShopInfoDTO> shopInfos = shopInfoService.getNoManager();

        return RestUtil.success(shopInfos);
    }



}

